package com.shiro.demo.project.system.content.controllers;

import com.shiro.demo.common.MessageUtils;
import com.shiro.demo.framework.aspectj.Log;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/secured")
public class ContentAccessController {
    private final static String PREFIX = "/secured";

    @Log(module = "ContentAccessController", action = "index")
    @GetMapping("/index")
    public String index(Model model){
        String username = (String)SecurityUtils.getSubject().getPrincipal();

        Session simpleSession = (Session)SecurityUtils.getSubject().getSession();
        model.addAttribute("username", username);
        model.addAttribute("session", simpleSession);
        model.addAttribute("host", simpleSession.getHost());
        model.addAttribute("message", MessageUtils.format("default",1,2,3));

        return PREFIX + "/index";
    }

    @GetMapping("/starter")
    public String starter(){
        return PREFIX + "/starter";
    }

    @GetMapping("/dashboard")
    public String dashboard(){
        return PREFIX + "/dashboard";
    }
}
